package cn.xuewenbao.edu.mapper;

import cn.xuewenbao.edu.entity.Comment;
import cn.xuewenbao.edu.entity.vo.CommentVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 评论表 Mapper 接口
 * </p>
 *
 * @author mafayu
 * @since 2021-03-26
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {


    @Select("SELECT c.commentId, c.userId, m1.username userName, m1.avatar userAvatar, c.parentCommentId, c.targetCommentId, c.targetUserId, m2.username targetUserName, m2.avatar targetUserAvatar, c.contentId, c.columnType, c.content, c.gmt_create, c.gmt_modified \n" +
            "FROM `comment` c\n" +
            "LEFT JOIN member m1 ON m1.id = c.userId\n" +
            "LEFT JOIN member m2 ON m2.id = c.targetUserId\n" +
            "WHERE c.contentId = #{contentId} AND c.columnType = #{columnType}")
    List<CommentVo> getCommentList(String contentId, String columnType);
}
